﻿using System;
using System.Linq;
using System.Reflection;

namespace ExcelReader.Helper
{
    internal static class ColumnMapperHelper
    {
        internal static string GetColumnNameInExcel(Type type, string fieldName)
        {
            PropertyInfo prop = type.GetProperties().FirstOrDefault(p => p.Name.Equals(fieldName));

            if (prop != null)
            {
                object[] attrs = prop.GetCustomAttributes(true);
                return attrs.Select(attr => attr as ModelHelper.ColumnMapper).Select(columnAttr => columnAttr.ColumnName).FirstOrDefault();
            }

            return null;
        }
    }
}
